import type { InternalRowData, TableBaseColumn } from 'naive-ui/lib/data-table/src/interface';
import type { VNodeChild } from 'vue';

import type TableFieldType from '@/components/table/src/types/field-type';
import type {
  BooleanTableFieldOptions,
  IconTableFieldOptions,
  NumberTableFieldOptions,
  TagTableFieldOptions,
  TextTableFieldOptions,
} from '@/components/table/src/types/component-type';

export interface BasicTableColumn<T = InternalRowData> extends Omit <TableBaseColumn<T>, 'key' | 'render'> {
  /**
   * key
   */
  key: string;
  /**
   * 排序
   */
  sort?: number;
  /**
   * 是否展示
   */
  display?: boolean;
  /**
   * 字段类型
   */
  fieldType: TableFieldType;
  /**
   * 格式化器
   */
  formatter?: (value: any, rowData?: Recordable) => string;
  /**
   * 自定义渲染
   *
   * @param value 值
   * @param rowData 行数据
   * @returns 虚拟Node
   */
  render?: (value: any, rowData?: Recordable) => VNodeChild;
  /**
   * 默认值
   */
  defaultValue?: string | boolean | number | ((rowData: T) => string | boolean | number);
  /**
   * 布尔类型字段选项
   */
  booleanOptions?: BooleanTableFieldOptions;
  /**
   * 文本类型字段选项
   */
  textOptions?: TextTableFieldOptions;
  /**
   * 图标类型字段选项
   */
  iconOptions?: IconTableFieldOptions;
  /**
   * 数值类型字段选项
   */
  numberOptions?: NumberTableFieldOptions;
  /**
   * 标签类型字段选项
   */
  tagOptions?: TagTableFieldOptions;
}

export interface TableActionType {
  reload: (opt?: any) => Promise<void>;
  emits?: any;
  getColumns: (opt?: any) => BasicTableColumn[];
  setColumns: (keys: string[]) => void;
  getCacheColumns: (onlyKey: boolean) => BasicTableColumn[] | string[];
  setCacheColumnsField: (key: string | undefined, value: Partial<BasicTableColumn>) => void;
  setSelection: (selection: boolean) => void;
}
